class Solution(object):
    def minCostSetTime(self, startAt, moveCost, pushCost, targetSeconds):
        h = targetSeconds // 60
        m = targetSeconds % 60
        if h < 100:
            time_list = [[h, m]]
        else:
            time_list = []
        if m <= 39 and h >= 1:
            time_list.append([h - 1, m + 60])
        def cal(h, m):
            if h == 0:
                if m < 10:
                    t = [m % 10]
                else:
                    t = [m // 10, m % 10]
            else:
                if h < 10:
                    t = [h, m // 10, m % 10]
                else:
                    t = [h // 10, h % 10, m // 10, m % 10]
            ans = len(t) * pushCost
            if t[0] != startAt:
                ans += moveCost
            for i in range(1, len(t)):
                if t[i] != t[i - 1]:
                    ans += moveCost
            return ans

        min_count = float('inf')
        for h, m in time_list:
            min_count = min(min_count, cal(h, m))
        return min_count


data = Solution()
print(data.minCostSetTime(7, 220, 479, 6000))
